<?php
session_start();
include_once("conn.php");
$username = $_POST['username'];
$sql = "SELECT *,case when m.numbers is null then 0 else m.numbers end nb,case when m.lastposttime is null then '未发贴' else m.lastposttime end lp from (SELECT
  u.id,
	u.username,
	u.pic,
	u.postDate,
	u.nickname	
FROM
	userinfo u where username = '".$_SESSION['username']."')
u 
	LEFT JOIN (
SELECT
	main.*,
	title,
	posttime as lastposttime
FROM
	( SELECT count( 1 ) AS numbers, userid, max( id ) AS mainid FROM maintopic GROUP BY userid ) main,
	maintopic 
WHERE
	main.mainid = id 
	) m ON u.id = m.userid
	left JOIN (SELECT userid,max(posttime) as lastreplytime from subtopic GROUP BY userid) s on u.id =s.userid
	";
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows($result)){
    $a['error'] = 0;
    $a['info'] = mysqli_fetch_array($result);
}
else{
    $a['error'] = 1;
    $a['errMsg'] = '未查询到当前用户信息';
}
echo json_encode($a);

?>